<template>
	<view class="addFormMian">
		<view class="formBox">
			<view class="inputItem">
				<view class="txt">联系人：</view>
				<input class="myinput" v-model="formData.memberName"/>
			</view>
			<view class="inputItem">
				<view class="txt">联系电话：</view>
				<input class="myinput" v-model="formData.memberPhone"/>
			</view>
			<view class="inputItem">
				<view class="txt">联系地址：</view>
				<input class="myinput" v-model="formData.memberAddress"/>
			</view>
			<!-- <view class="inputItem">
				<view class="txt">有无疾病史：</view>
				<view class="rdbox">
					<input class="myinput" v-model="formData.k"/>
				</view>
			</view> -->
			<view class="fbtbox" @click="comfirm">{{aidOrderType==1?'确认需要':'确认加入'}}</view>
		</view>
	</view>
</template>

<script>
	import {defineComponent,reactive,toRefs,onMounted,getCurrentInstance,computed} from 'vue'
	import {onLoad,onShow} from '@dcloudio/uni-app'
	import { useStore } from 'vuex'
	import {createAccompanyOrder,createAidOrder} from "@/api/index.js"
	import {toast} from "@/utils/common.js"
	export default defineComponent({
		components:{
			
		},
		props:{
			id:'',
			topCtgId:'',
			aidOrderType:'' // 1需要服务，2成为志愿者
		},
		setup(props,context) {
			const store = useStore()
			const {proxy} = getCurrentInstance()
			
			const state = reactive({
				formData:{},
				userInfo:computed(()=>store.state.base.userInfo)
			})
			
			onMounted(()=>{
				state.formData.memberName = state.userInfo.name
				state.formData.memberPhone = state.userInfo.phone
				state.formData.memberAddress = state.userInfo.address
			})
			
			const comfirm = async ()=>{
				if(!state.formData.memberName){
					return toast('请输入联系人姓名')
				}else if(!state.formData.memberPhone){
					return toast('请输入联系电话')
				}else if(!state.formData.memberAddress){
					return toast('请输入联系地址')
				}
				state.formData.id = props.id
				console.log("aidOrderType:",props.aidOrderType)
				let res = {}
				let tips = '报名成功！'
				if(props.topCtgId==14){ // 居家互助
					let tips = '提交成功！'
					res = await createAidOrder(state.formData)
				}else{
					res = await createAccompanyOrder(state.formData)
				}
				
				if(res.code == 0){
					toast(tips)
					context.emit('complete',res)
				}else{
					toast(res.msg)
				}
			}
			
			return {
				...toRefs(state),
				comfirm
			}
		}
	})
</script>

<style lang="scss" scoped>
	.addFormMian{
		box-sizing: border-box;
		width: 100%;
		padding:20rpx 20rpx;
		.formBox{
			box-sizing: border-box;
			width: 100%;
			background: #fba70e;
			border-radius:40rpx ;
			padding:0 30rpx;
			.inputItem{
				display: flex;
				height: 90rpx;
				line-height:90rpx;
				border-bottom:1px solid #fcf7ee;
				padding:0 10rpx;
				font-size: 30rpx;
				.txt{
					width: 180rpx;
					color: #ffffff;
				}
				.myinput{
					display: block;
					height: 100%;
					line-height:90rpx; 
					vertical-align:middle;
					font-size: 30rpx;
					color: #fff;
				}
				.desc{
					flex: 1;
					text-align: right;
				}
				.rdbox{
					flex: 1;
					display: flex;
					align-items: center;
				}
			}
			.fbtbox{
				padding: 30rpx 0;
				font-size: 32rpx;
				font-weight: 600;
				text-align: center;
				color: #fff;
			}
		}
	}
</style>
